<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp" %>

<SCRIPT type="text/javascript">
		<!--
		var setting = {
			view: {
				selectedMulti: false
			},
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		$(document).ready(function(){
			$("#saveMenuBtn").bind("click", function(){
				var zTree = $.fn.zTree.getZTreeObj("treeMenu"),
			     nodes = zTree.getCheckedNodes(true);
			    var menuList=[];
			     for (var i = 0; i < nodes.length; i++) {
			       var menuObj={};
			    	menuObj.id=nodes[i].id;
			    	menuObj.name = nodes[i].name;
			        menuObj.typeFlag = nodes[i].typeFlag;
			        menuObj.pId = nodes[i].pId;
			        menuObj.intID = nodes[i].intID;
			        menuList.push(menuObj);
			    }
			    $("#roleMenuFunc").val(JSON.stringify(menuList));
			    $("#roleMenuForm").submit();
			});
			
			$.ajax({   
			    url:'${ctx}/management/menu/loadMenuInfo.do',   
			    type:'post',   
			    data:'roleId=${roleId}',   
			    async : true, //默认为true 异步   
			    error:function(){   
			       alert('error');   
			    },   
			    success:function(data){
			     	setting.check.chkboxType = { "Y":"p","N":"s"};
			       $.fn.zTree.init($("#treeMenu"), setting,eval('(' + data + ')'));
			    }
			});

			//$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		});
		//-->
	</SCRIPT>

<div class="bjui-pageContent tableContent">
  <form id="roleMenuForm" action="${ctx}/management/role/saveRoleMenus.do" data-toggle="validate" data-reload-navtab="true">
	 <input type="hidden"  name="roleId" value="${roleId}">
	 <input type="hidden"  id="roleMenuFunc" name="roleMenuFunc" value="">
    <ul id="treeMenu" class="ztree"></ul>
   </form>
</div>
<div class="bjui-pageFooter">
    <ul>
       <li id="checkCount"></li>
        <li><button type="button" class="btn-close" data-icon="close">取消</button></li>
        <li><button type="button" id="saveMenuBtn" class="btn-default" data-icon="save">全部保存</button></li>
    </ul>
</div>
